##

ALLIANCE_TOP	= /opt/alliance-5.0

ENV_ASIMUT	= MBK_CATAL_NAME=CATAL_ASIMUT

ENV_COUGAR	= MBK_SPI_MODEL=$(ALLIANCE_TOP)/etc/spimodel.cfg ;\
		  export MBK_SPI_MODEL;\
		  MBK_IN_PH=ap ;\
		  export MBK_IN_PH;\
		  MBK_OUT_LO=spi;\
		  export MBK_OUT_LO
	
all: translate check-behavioral synthesis place-route transistors

#------------------------------------------------------------------------------
# Translate to Alliance VHDL

translate: inst_memory.vbe

inst_memory.vbe: inst_memory.vhdl     # Lleva de vhdl a alliance
	vasy -Vaop -I vhdl inst_memory.vhdl

#------------------------------------------------------------------------------
# Simulate

check-behavioral:  inst_memory.vbe test_c.pat result_sim.pat

test_c.pat: test_c.c
	genpat test_c

result_sim.pat: inst_memory.vbe test_c.pat
	$(ENV_ASIMUT) asimut -b inst_memory test_c result_sim

view-behav: result_sim.pat
	xpat -l result_sim 

#------------------------------------------------------------------------------
# Synthesize

synthesis: inst_memory.vst

inst_memory.vst: inst_memory_boom.vbe
	boog inst_memory_boom inst_memory_boog
	loon inst_memory_boog inst_memory_loon

inst_memory_boom.vbe: inst_memory.vbe
	boom inst_memory inst_memory_boom

view-gates: inst_memory_loon.vst
	xsch -l inst_memory_loon

#------------------------------------------------------------------------------
# Place and Route

place-route: synthesis inst_memory_ocp.ap inst_memory_nero.ap \
		inst_memory_s2r.cif

inst_memory_ocp.ap: inst_memory_loon.vst
	ocp inst_memory_loon inst_memory_ocp

inst_memory_nero.ap: inst_memory_ocp.ap inst_memory_loon.vst
	nero -p inst_memory_ocp inst_memory_loon inst_memory_nero

inst_memory_s2r.cif: inst_memory_nero.ap
	s2r inst_memory_nero inst_memory_s2r

view-place: synthesis inst_memory_ocp.ap
	graal -l inst_memory_ocp

view-route: synthesis inst_memory_nero.ap
	graal -l inst_memory_nero

view-real: synthesis inst_memory_s2r.cif
	dreal -l inst_memory_s2r

#------------------------------------------------------------------------------
# Extract transistor netlist

transistors: place-route inst_memory_transistors.spi

inst_memory_transistors.spi: inst_memory_nero.ap
	$(ENV_COUGAR); cougar -t inst_memory_nero inst_memory_transistors

spice-inst_memory: inst_memory_transistors.spi
	$(ENV_COUGAR); xsch -I spi -l inst_memory_transistors

clean:
	rm -rf  *.pat \
		*.vst \
		*.xsc \
		*.vbe \
		*.boom \
		*.ap \
		*.cif \
		*.spi \
		*.dat
